package com.amazon.web.controller;


import com.amazon.bo.KeyWords;
import com.amazon.bo.ProductClass;
import com.amazon.service.I18nService;
import com.amazon.service.ProductClassService;
import com.amazon.web.util.ApiResponse;
import com.amazon.web.util.OSSManageUtil;
import com.amazon.web.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value="productClass")
public class ProductClassController {
    @Value("${is.open.cms}")
    public String isOpenCms;


    private static final String APP_ID = "20180715000185622";
    private static final String SECURITY_KEY = "RtGMlsmDQUDfmQ6Ddi5L";

    @Resource
    private OSSManageUtil ossManageUtil;

    @Resource
    ProductClassService productClassService;

    @Autowired
    I18nService i18nService;

    @RequestMapping(value = "productClassSave", method = RequestMethod.POST)
    public Object productClassSave(ProductClass p){
        ProductClass old=productClassService.getProductClassBycode(p.getProductClassCode());
        if(old!=null){
            old.setProductClassCode(p.getProductClassCode());
            old.setProductClassName(p.getProductClassName());

            boolean flag =productClassService.update(old);
            return flag;
        }else{
            boolean flag=productClassService.save(p);
            return flag;
        }
    }
    @RequestMapping(value = "getProductClassList", method = RequestMethod.GET)
    public ApiResponse getKeyWordsList(int page, int pagesize){
        Object list=productClassService.getClassList(page,pagesize);
        int total = productClassService.getClassCount();
        return ResponseUtil.getSuccessResponse(list, total);
    }





}
